import { createEventService } from "../../service/event-data";
import { yesterdayDate } from "../utils";

export const writeDB = async (result: { [key: string]: any } = {}) => {
  const keys = Object.keys(result);
  const dataList = keys.map((key) => ({
    eventKey: key,
    eventData: result[key],
    eventDate: yesterdayDate(),
  }));

  try {
    await createEventService(dataList);
    console.error("日志分析入库成功");
  } catch (err) {
    console.error("日志分析入库失败", err);
  }
};
